/* Autostop
 *
 * Copyright (c) Maciej Gajewski, Grzegorz Latarowski
 * http://code.google.com/p/autostop-automaty-drogowe
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version. NO WARRANTY OF ANY KIND is expressed or implied.
 */

#include "serverlistener.h"
	
// -------------------- constructor -------------------
ServerListener::ServerListener() : QTcpServer()
{
	// nope
}

// -------------------- destructor -------------------
ServerListener::~ServerListener()
{
	// nope
}

// ---------------- listen ----------------------
/// Listen for incoming connection infinitely (or unitl error)
void ServerListener::listen( quint16 port )
{
	QTcpServer::listen( QHostAddress::Any, port );

	while ( waitForNewConnection(-1) )
	{
		// nothing, processing in incomingConnection()
	}
}

// ------------------- incoming connection -------
void ServerListener::incomingConnection( int socket )
{
	ServerThread *thread = new ServerThread( socket, this );
	connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
	thread->start();
}


// eof
